package com.teatrace.commons.hibernate3.support;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import org.hibernate.Session;

public class SaveAndRefreshObjectSessionProxy implements InvocationHandler {

	private Session session;
	
	public SaveAndRefreshObjectSessionProxy(Session session) {
		this.session = session;
	}
	
	
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		Object returns = method.invoke(session, args);
		if("save".equals(method.getName())) {
			session.clear();
		} else if("saveOrUpdate".equals(method.getName())) {
			session.clear();
		}
		return returns;
	}

}
